#include "../include/SlowBullet.h"
#include "../include/Global.h"

#include "SDL/SDL.h"
#include "SDL/SDL_opengl.h"

SlowBullet::SlowBullet():Bullet()
{
    colorR = 0.0;
    colorG = 0.0;
    colorB = 0.8;
    Pos = Position(0,0);
    width = 0.25;
    stepSize = 0.2;
    height = 0.25;
    depth = .25;
    range = 1;
    minionIndex=0;


}

void SlowBullet :: hitEffect(std::vector<Minion> &min, int i)
{
    for(int j = 0; j < min.size(); j++)
    {
        if(getDistance(min[i].getPos().Xpos, min[j].getPos().Xpos, min[i].getPos().Ypos, min[j].getPos().Ypos) <= 1)
               min[j].SlowStatus(0.05, 2);
    }
    min[i].changeHealth(min[i].getHealth() - bulletDamage);
            if(min[i].getHealth()<= 0 && min.size() != 0)
            {
                min.erase(min.begin()+i);
                deadMinionIndex = i;
            }
            Pos = Position(0,0);
            Zpos = 2.4;
            Timer.start();
}

void SlowBullet :: hitEffect(std::vector<Minion> &min, Position target)
{
    for(int j = 0; j < min.size(); j++)
    {
        if(getDistance(target.Xpos, min[j].getPos().Xpos, target.Ypos, min[j].getPos().Ypos) <= 2)
        {
               min[j].SlowStatus(0.05, 2);
               // min[j].changeHealth(min[j].getHealth() - bulletDamage);
            if(min[j].getHealth()<= 0 && min.size() != 0)
            {
                min.erase(min.begin()+j);

                //Since min.erase will change the index of ever minion in the vector
                //after the one being erased, we need to update the index of those minions.
                for(int newIndex = j; newIndex < min.size(); newIndex++)
                {
                    min[newIndex].SetIndex(newIndex);
                }
            }
            Pos = Position(0,0);
            Zpos = 2.4;
            Timer.start();

        }
    }
}


SlowBullet::~SlowBullet()
{
    //dtor
}
